import store from 'storejs'
import { OauthType } from '@/api/user'
export function generateKey(key: string) {
  return process.env.VUE_APP_NAME ? `${process.env.VUE_APP_NAME}__${key}` : ''
}

const storageKey = generateKey('oauth')

export const isLogin = async () => {
  const res = await store.get(storageKey)
  return !!res && !!res.access_token
}

export const getOauth = () => {
  return store.get(storageKey)
}

export const setOauth = (Oauth: OauthType) => {
  return store.set(storageKey, Oauth)
}

export const clearOauth = () => {
  return store.remove(storageKey)
}
// ----------------------------------------------------
const cacheUserInfoKey = generateKey('userInfo')

export const getCacheUserInfo = () => {
  return store.get(cacheUserInfoKey)
}

export const setCacheUserInfo = (userInfo: any) => {
  return store.set(cacheUserInfoKey, userInfo)
}

export const clearCacheUserInfo = () => {
  return store.remove(cacheUserInfoKey)
}
